package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.mapper.entity.Clothing;
import com.example.demo.mapper.entity.Coupons;
import com.example.demo.mapper.entity.CouponsView;
import com.example.demo.mapper.entity.StudentCoupons;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CouponsManageMapper extends BaseMapper<Coupons> {
    @Select("SELECT * FROM coupons_view WHERE coupons_type = 1")
    List<CouponsView> getVoucherList();
    @Select("SELECT * FROM coupons_view WHERE coupons_type = 2")
    List<CouponsView> getFullDiscountCouponList();
    @Select("SELECT * FROM coupons_view WHERE coupons_type = 3")
    List<CouponsView> getDiscountCouponList();
    @Select("SELECT * FROM coupons_view WHERE coupons_type = 4")
    List<CouponsView> getExchangeCouponList();
    @Select("SELECT * FROM coupons_view WHERE coupons_type = #{couponType}")
    List<CouponsView> getCouponList(int couponType);

    @Insert("INSERT INTO coupons(coupons_name, coupons_type, description, value, minimum_amount, product_name, " +
            "start_date, end_date, created_at, updated_at, advertiser_id, `condition`, state, product_image_url) " +
            "VALUES(#{couponsName}, #{couponsType}, #{description}, #{value}, #{minimumAmount}, #{productName}, " +
            "#{startDate}, #{endDate}, #{createdAt}, #{updatedAt}, #{advertiserId}, #{condition}, #{state}, #{productImageUrl})")
    int addCoupons(Coupons request);
    @Select("SELECT DISTINCT user_name, advertiser_id " +
            "FROM coupons_view;")
    List<CouponsView> getCompanyList();

    @Select("SELECT * FROM coupons_view WHERE coupons_id = #{couponsId}")
    List<CouponsView> getCouponDataList(int couponsId);

    @Delete("<script>" +
            "DELETE FROM coupons" +
            " WHERE coupons_id IN" +
            " <foreach collection='list' index='index' open='(' separator=',' close=')' item='couponsList' >" +
            "   #{couponsList.couponsId}" +
            " </foreach>" +
            "</script>")
    void batchDeleteClothing(List<Coupons> couponsList);
    @Update("UPDATE `coupons` SET state = #{state} " +
            "WHERE coupons_id = #{couponsId}")
    void updateState(CouponsView request);

    @Select("SELECT product_image_url FROM coupons WHERE coupons_id = #{couponsId}")
    String selectPicById(int couponsId);

    @Update("UPDATE `coupons` SET product_image_url = #{productImageUrl} " +
            "WHERE coupons_id = #{couponsId}")
    void placeCouponsPic(Coupons request);

    @Select("SELECT * FROM student_coupons WHERE status = 1")
    List<StudentCoupons> getStudentCouponsList();
    @Select("SELECT * FROM student_coupons WHERE status = 2")
    List<StudentCoupons> getRedeemList();
}
